<template>
  <tl-sub-page :append-to-body="true" :render="render" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1000px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit || disableSave">
      <el-row>
        <el-col :span="24">
          <el-form-item label="所属里程碑及任务" prop="milepostname">
            <el-input v-model="model.milepostname" :disabled="true" class="tl-ref-selector">
              <el-button slot="append" type="primary" icon="el-icon-search" @click="openMpmProjectMilepostDialog" v-if="!disableSave"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="任务类型" prop="tasktype">
            <el-input v-model="model.tasktype"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="任务优先级" prop="taskpriority">
            <el-input v-model="model.taskpriority"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="任务名称" prop="taskname" :rules="rules.validateRequire">
            <el-input v-model="model.taskname"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="任务内容" prop="taskdetail" :rules="rules.validateRequire">
            <el-input v-model="model.taskdetail" type="textarea" maxlength="1000" show-word-limit :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="责任人" prop="responsiblecode" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.responsiblecode" :initDisplayData.sync="model.responsible" dataType="code" :singleSelect="true" :disabled="disableSave"></tl-ref-user>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="责任人工号" prop="responsiblecode" :rules="rules.validateRequire">
            <el-input v-model="model.responsiblecode" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="计划开始日期" prop="planstartdate" :rules="rules.validateRequire">
            <el-date-picker v-model="model.planstartdate" type="date" placeholder="年-月-日" value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="计划完成日期" prop="planenddate" :rules="rules.validateRequire">
            <el-date-picker v-model="model.planenddate" type="date" placeholder="年-月-日" value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- <el-row>
        <el-col :span="12">
          <el-form-item label="任务进度" prop="taskschedule">
            <el-input-number v-model="model.taskschedule" :disabled="true" style="width:95%" controls-position="right">
            </el-input-number><span>%</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="任务状态" prop="taskstate">
            <el-select v-model="model.taskstate" filterable clearable :disabled="true">
              <el-option v-for="item in codeModel.taskstateList" :key="item.code" :label="item.name"
                :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row> -->
      <!-- <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row> -->
    </el-form>
    <tl-approval-history ref="history" sourceType="MpmProjectTask" :sourceId="model.id" />
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave">
        <svg-icon icon-class="save" />保存
      </el-button>
      <el-button type="primary" @click="doSubmitApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval">
        <svg-icon icon-class="send" />提交审批
      </el-button>
      <tl-attachment sourceType="MpmProjectTask" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory">
        <svg-icon icon-class="list" />审批历史
      </el-button>
      <el-button type="primary" @click="doDelApproval" :loading="delApprovalLoading" v-if="!disableEditSubmit" :disabled="disableDelApproval">
        <svg-icon icon-class="undo" />取消审批
      </el-button>
    </div>
    <tlmpmProject-milepost-ref ref="mpmProjectMilepostRef" @confirm="getMpmProjectMilepostData" :isSingleSelect="false" :externalQueryParam="externalQueryParamForPool">
    </tlmpmProject-milepost-ref>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
import tlmpmProjectMilepostRef from '@/views/mpm/mpmProjectMilepost/refList'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: { tlmpmProjectMilepostRef },
  data() {
    return {
      moduleTitle: '项目任务',
      urlPrefix: '/mpm/projectTask/',
      url: {
        // 额外的url
      },
      externalQueryParamForPool: {}
    }
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'applyorgcode', this.org.code)
        this.$set(this.model, 'applyorgname', this.org.name)
        this.$set(this.model, 'applydeptcode', this.dept.code)
        this.$set(this.model, 'applydeptname', this.dept.fullname)
        this.$set(this.model, 'applyusercode', this.user.code)
        this.$set(this.model, 'applyusername', this.user.name)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'taskschedule', '0')
        this.$set(this.model, 'taskstate', '0')
      }
    },
    loaded() {
      // 页面加载完毕执行
      if (!this.isAdd && this.model.docno) {
        this.title = this.title + `（单据编号：${this.model.docno}）`
      }
      this.model.taskstate = String(this.model.taskstate)
    },
    /** 打开里程碑及任务参照 */
    openMpmProjectMilepostDialog() {
      const { projectcode } = this.model
      this.externalQueryParamForPool = {
        qry_projectcode: projectcode
      }
      this.$refs.mpmProjectMilepostRef.visible = true
    },
    /** 获取里程碑及任务参照数据 */
    getMpmProjectMilepostData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'milepostname', selectionRow.milepostname)
      this.$set(this.model, 'milepostcode', selectionRow.operatecode)
    }
  }
}
</script>

